package com.spsy.order.service.impl;

import com.spsy.common.core.domain.R;
import com.spsy.order.config.DelayedQueueConfig;
import com.spsy.order.service.MqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: liuzhiping
 * @date: 2025/5/14 15:32
 **/
@Service
@Slf4j
public class MqServcieImpl implements MqService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public R sendMsg(String message, Integer delayTime) {
        log.info("当前时间：{}，2209a 发送一条时长{}毫秒的消息给延迟队列：{}", new Date(),delayTime,message);
        rabbitTemplate.convertAndSend(DelayedQueueConfig.DELAYED_EXCHANGE_NAME,DelayedQueueConfig.DELAYED_ROUTING_KEY,message, msg -> {
            //发送消息的时候延迟时长
            msg.getMessageProperties().setDelay(delayTime);

            return msg;
        });
        return R.ok();
    }

}
